
import $http from '@/axios'
import {handleSuccess,handleError} from "../common.js";
import {Message} from "@arco-design/web-vue";

/**
 * 部门管理模块的相关API接口
 * @type {{getDeptList: (function(): Promise<*>), addDept: (function(*): Promise<*>), updateDept: (function(*): Promise<*>), deleteDept: (function(*): Promise<*>)}}
 */
export const deptAPI = {
    getDeptList: async () => {
        return $http.get('/dept/list')
            .then(res => handleSuccess(res, '获取部门列表'))
            .catch(error => handleError(error, '获取部门列表', '服务器连接异常'))
    },
    getDept: async (id) => {
        return $http.get(`/dept/${id}`)
            .then(res => handleSuccess(res, '获取部门详情'))
            .catch(error => handleError(error, '获取部门详情', '服务器连接异常'))
    },
    addDept: async (data) => {
        return $http.post('/dept/add', data)
            .then(res => handleSuccess(res, '新增部门'))
            .catch(error => handleError(error, '新增部门', '服务器连接异常'))
    },
    updateDept: async (data) => {
        return $http.put('/dept/update', data)
            .then(res => handleSuccess(res, '修改部门'))
            .catch(error => handleError(error, '修改部门', '服务器连接异常'))
    },
    deleteDept: async (id) => {
        return $http.delete(`/dept/delete/${id}`)
            .then(res => handleSuccess(res, '删除部门'))
            .catch(error => handleError(error, '删除部门', '服务器连接异常'))
    }

}
